<template>
  <div>
    <swiper class="swiper" :options="swiperOption">
      <swiper-slide v-for="item of data.recommend" :key="item.goodsId">
        <van-image :src="$resetUrl(item.image)" />
        <p class="goods-content">
          {{ item.goodsName }}
        </p>
        <p class="goods-content">
          {{ toMoney(toFixed(item.price)) }}
          ({{ toMoney(toFixed(item.mallPrice)) }})
        </p>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/swiper.min.css";
export default {
  props: {
    data: {
      type: Object,
      required: true,
    },
  },
  components: {
    Swiper,
    SwiperSlide,
  },
  data() {
    return {
      swiperOption: {
        slidesPerView: 3,
        spaceBetween: 30,
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
      },
    };
  },
  methods: {
    toFixed(result) {
      //过滤小数点后两位

      if (typeof result !== "number") {
        result = Number(result);
      }
      return result.toFixed(2);
    },
    toMoney(money, type = "¥") {
      //转换钱币类型
      return type + money;
    },
  },
};
</script>

<style scoped>
.goods-content {
  font-size: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
</style>
